#include "myconfig.h"
#include <QSettings>
#include <QDebug>

#define SETFILENAME "config.ini"
#define NETGROUPNAME    "NetSettings"
#define NETGATEWAYPORT  "NetGatewayPort"
#define NETClientPORT   "NetClientPort"


MyConfig::MyConfig(QObject *parent) : QObject(parent)
{

}

void MyConfig::init()
{
    QSettings set(SETFILENAME, QSettings::IniFormat);
    //开始配置网络组
    set.beginGroup(NETGROUPNAME);
    QStringList list = set.childKeys();
    //判断配置项是否在组内，如果不在，新增配置项
    if(!list.contains(NETGATEWAYPORT))
    {
        set.setValue(NETGATEWAYPORT, 10001);
    }
    if(!list.contains(NETClientPORT))
    {
        set.setValue(NETClientPORT, 10002);
    }
    set.endGroup();
}

int MyConfig::getNetGateWayPort()
{
    QSettings set(SETFILENAME, QSettings::IniFormat);
    //开始配置网络组
    set.beginGroup(NETGROUPNAME);
    int re = set.value(NETGATEWAYPORT).toInt();
    set.endGroup();
    return re;
}

int MyConfig::getNetClientPort()
{
    QSettings set(SETFILENAME, QSettings::IniFormat);
    //开始配置网络组
    set.beginGroup(NETGROUPNAME);
    int re = set.value(NETClientPORT).toInt();
    set.endGroup();
    return re;
}







